package org.lds.scheduled.job.admin.client;

import lombok.RequiredArgsConstructor;
import org.lds.scheduled.job.admin.client.core.model.request.RegisterJobRequest;
import org.lds.scheduled.job.admin.client.core.model.request.RegisterWorkerRequest;
import org.lds.scheduled.job.admin.client.core.model.response.RegisterJobResponse;
import org.lds.scheduled.job.admin.client.properties.AdminClientProperties;
import org.lds.scheduled.job.common.model.dto.ResultDTO;
import org.lds.scheduled.job.common.util.RestUtil;
import org.springframework.core.ParameterizedTypeReference;

@RequiredArgsConstructor
public class AdminClient {
    private final AdminClientProperties adminClientProperties;

    public AdminClientProperties getAdminClientProperties() {
        return adminClientProperties;
    }

    public ResultDTO<RegisterJobResponse> registerJob(RegisterJobRequest request) {
        return RestUtil.post(adminClientProperties.getAdminAddress() + "/api/remote/job/register", request, new ParameterizedTypeReference<ResultDTO<RegisterJobResponse>>() {});
    }

    public ResultDTO<Long> registerWorker(RegisterWorkerRequest request) {
        return RestUtil.post(adminClientProperties.getAdminAddress() + "/api/remote/worker/register", request, new ParameterizedTypeReference<ResultDTO<Long>>() {});
    }
}
